1 package activity;
2
3 import java.lang.*;
4 import javax.swing.*;
5 import java.awt.*;
6 import javax.swing.border.*;
7 import java.awt.event.*;
8 import java.sql.*;
9 import attr.*;
10
11 public class CustomerActivity extends JFrame implements ActionListener {
12 private JPanel panel;
13 private Customer customer;
14 private JButton buttonLogout, buttonProfile, buttonViewProduct, buttonMyProduct;
15 private JLabel title, header;
16 public CustomerActivity(String userId) {
17 super("Dashboard - Customer");
18
19 this.setSize(Theme.GUI_WIDTH, Theme.GUI_HEIGHT);
20 this.setResizable(false);
21 this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
22 this.setLocationRelativeTo(null);
23
24 panel = new JPanel();
25 panel.setLayout(null);
26 panel.setBackground(Theme.BACKGROUND_PANEL);
27
28 customer = new Customer(userId);
29 customer.fetch();
30
31 title = new JLabel("Welcome, "+userId);
32 title.setBounds(30, 40, userId.length()*30+220,75);
33 title.setOpaque(true);
34 title.setBorder(new EmptyBorder(0,20,0,0));
35 title.setFont(Theme.FONT_TITLE);
36 title.setForeground(Theme.COLOR_TITLE);
37 panel.add(title);
38
39 buttonLogout = new JButton("Logout");
40 buttonLogout.setBounds(Theme.GUI_WIDTH-140, 40, Theme.BUTTON_PRIMARY_WIDTH,30);
41 buttonLogout.setFont(Theme.FONT_BUTTON);
42 buttonLogout.setBackground(Color.WHITE);
43 buttonLogout.setForeground(Theme.COLOR_TITLE);
44 buttonLogout.addActionListener(this);
45 panel.add(buttonLogout);
46
47 buttonProfile = new JButton("My Profile");
48 buttonProfile.setBounds(Theme.GUI_WIDTH-150, 80, 120,30);
49 buttonProfile.setFont(Theme.FONT_BUTTON);
50 buttonProfile.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
51 buttonProfile.setForeground(Theme.COLOR_BUTTON_PRIMARY);
52 buttonProfile.addActionListener(this);
53 panel.add(buttonProfile);
54
55 buttonViewProduct = new JButton("View Product");
56 buttonViewProduct.setBounds(60, 160, 200, 30);
57 buttonViewProduct.setFont(Theme.FONT_BUTTON);
58 buttonViewProduct.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
59 buttonViewProduct.setForeground(Theme.COLOR_BUTTON_PRIMARY);
60 buttonViewProduct.addActionListener(this);
61 panel.add(buttonViewProduct);
62
63 buttonMyProduct = new JButton("Purchase History");
64 buttonMyProduct.setBounds(60, 190, 200, 30);
65 buttonMyProduct.setFont(Theme.FONT_BUTTON);
66 buttonMyProduct.setBackground(Theme.BACKGROUND_BUTTON_PRIMARY);
67 buttonMyProduct.setForeground(Theme.COLOR_BUTTON_PRIMARY);
68 buttonMyProduct.addActionListener(this);
69 panel.add(buttonMyProduct);
70
71 header = new JLabel();
72 header.setBackground(Theme.BACKGROUND_HEADER);
73 header.setOpaque(true);
74 header.setBounds(0, 0, Theme.GUI_WIDTH, 75);
75 panel.add(header);
76
77 this.add(panel);
78 }
79
80 public void actionPerformed(ActionEvent ae) {
81 if (ae.getSource().equals(buttonProfile)) {
82 this.setVisible(false);
83 new MyProfileActivity(this, customer).setVisible(true);
84 }
85 else if (ae.getSource().equals(buttonLogout)) {
86 this.setVisible(false);
87 new LoginActivity().setVisible(true);
88 }
89 else if (ae.getSource().equals(buttonViewProduct)) {
90 this.setVisible(false);
91 new ViewProductActivity(this, customer).setVisible(true);
92 }
93 else if (ae.getSource().equals(buttonMyProduct)) {
94 this.setVisible(false);
95 new MyProductActivity(this, customer).setVisible(true);
96 }
97 else {}
98 }
99 }